/*---------------------------------------
/ Test Program for System Calls
/ Added in Project2
/
/ This Test is Process1 of testPart1
/ Process0 relies in testPart1.c
/
/ by OceanMaster
/---------------------------------------*/

#include "syscall.h"

/*Process1 of Part1 Test Case 5*/
int main()
{
	int lock;
	int condition;
	int tmp[2];

	WriteFormat("Process1: Process1 of testPart1 Test Case 5 is created \n",57,0,0);
	
	/*Temporarily Create Two new Lock and Condition to guess indexes of Lock and Condition held by Process 0*/
	lock = CreateLock("tmpLock",7);
	condition = CreateCondition("tmpCondition",12);
	DestroyLock(lock);
	DestroyCondition(condition);
	tmp[1] = lock = lock-1;
	tmp[0] = condition = condition-1;
	/*now lock and condition ahould be indexes of lock and condition held by process 0*/

	WriteFormat("Process1: Trying to Acquire Lock %d   \n",40,&lock,1);
	AcquireLock(lock);
	WriteFormat("          Acquire Lock %d should FAIL because it belong to process 0\n",70,&lock,1);
	
	WriteFormat("Process1: Trying to Release Lock %d   \n",40,&lock,1);
	ReleaseLock(lock);
	WriteFormat("          Release Lock %d should FAIL because it belong to process 0\n",70,&lock,1);
	
	WriteFormat("Process1: Trying to Destroy Lock %d   \n",40,&lock,1);
	DestroyLock(lock);
	WriteFormat("          Destroy Lock %d should FAIL because it belong to process 0\n",70,&lock,1);
	
	WriteFormat("Process1: Trying to Wait Condition %d with Lock %d   \n",55,tmp,2);
	WaitCondition(condition,lock);
	WriteFormat("          Wait Condition %d with Lock %d should FAIL because it belong to process 0\n",85,tmp,2);

	WriteFormat("Process1: Trying to Signal Condition %d with Lock %d \n",55,tmp,2);
	SignalCondition(condition,lock);
	WriteFormat("          Signal Condition %d with Lock %d should FAIL because it belong to process 0\n",87,tmp,2);
	
	WriteFormat("Process1: Trying to Broadcast Condition %d with Lock %d\n",57,tmp,2);
	BroadcastCondition(condition,lock);
	WriteFormat("          Broadcast Condition %d with Lock %d should FAIL because it belong to process 0\n",90,tmp,2);
	
	WriteFormat("Process1: Trying to Destroy Condition %d\n",42,&condition,1);
	DestroyCondition(condition);
	WriteFormat("          Destroy Condition %d should FAIL because it belong to process 0\n",75,&condition,1);
	WriteFormat("Process1: Exit\n",16,0,0);
	Exit(0);
}
